package com.yuexun.dhdoctor.module.Government;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.config.Contracts;
import com.yuexun.dhdoctor.module.Government.adapter.MenuAdapter;
import com.yuexun.dhdoctor.module.main.bean.MenuItemBean;
import com.yuexun.dhdoctor.module.webview.Act_WebView;

import org.kymjs.kjframe.ui.SupportFragment;
import org.kymjs.kjframe.utils.PreferenceHelper;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chenss on 2018/5/4 0004.
 */

public class Frag_Business extends SupportFragment {

    @Bind(R.id.government_menu)
    GridView governmentMenu;

    MenuAdapter menuAdapter;

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        View view = inflater.inflate(R.layout.frag_business, null);
        ButterKnife.bind(this, view);
        initData();
        return view;
    }

    @Override
    protected void initData() {

        menuAdapter = new MenuAdapter(governmentMenu, Contracts.businessMenuList, R.layout.item_menu);
        governmentMenu.setAdapter(menuAdapter);

        governmentMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MenuItemBean item = (MenuItemBean) parent.getItemAtPosition(position);
                Intent intent;
                switch (item.getPosition()) {
                    //值班安排
                    case 0:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", AppConfig.WEB_H5 + "duty.html" + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID)
                                + "&userId=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.USER_ID)
                                + "&departmentId=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.DEPARTMENTID));
                        getActivity().startActivity(intent);
                        break;
                    //特殊排班
                    case 1:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", AppConfig.WEB_H5 + "specialduty.html" + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        getActivity().startActivity(intent);
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
